charset="UTF-8"
Ext.onReady(function(){
	Ext.QuickTips.init();
     // example of custom renderer function
    function change(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '</span>';
        }
        return val;
    }

    // example of custom renderer function
    function pctChange(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '%</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '%</span>';
        }
        return val;
    }
    

    
	
  
var signRecord = Ext.data.Record.create([
				{name:'id'},  
             {name:'order'},
              {name:'patientIdentify'},  
              {name:'patientName'},  
              {name:'doctorName'},
              {name:'doctorTitle'},  
              {name:'departmentName'}, 
              {name:'hospitalName'}, 
              {name:'time'}, 
              {name:'workdate',type : 'date', dateFormat : 'Y-m-d'},  
               {name:'maxpatientnum'},
               {name:'nowpatientnum'}
		]);
    // create the data store
    var signStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({  
                	url:"querySignByPagePatient.action",  
                    method:"post"  
                }),  
        reader : new Ext.data.JsonReader({
        	totalProperty : 'totalProperty',
        	root : 'signVOList'
        	 }, 
        	 signRecord
        	 )
    });


	 var sm = new Ext.grid.CheckboxSelectionModel();  
	 
    var column = new Ext.grid.ColumnModel({
    		columns:[
    		new Ext.grid.RowNumberer(),
    		sm,
            {
            	header: "预约编号", 
            	width: 70, 
            	sortable: true, 
            	dataIndex: 'id'
            },
            {
            	header: "预约顺序", 
            	width: 70, 
            	sortable: true,
            	dataIndex: 'order'
            },
            {
            	header: "预约日期", 
            	width: 120,
            	sortable: true,
            	renderer: Ext.util.Format.dateRenderer('Y/m/d'), 
            	dataIndex: 'workdate'
            },
            {
            	header: "预约时间", 
            	width: 80,
            	sortable: true,
            	dataIndex: 'time'
            },
            {
            	header: "当前预约人数", 
            	width: 90,
            	sortable: true,
            	dataIndex: 'nowpatientnum'
            },
            {
            	header: "最大预约人数", 
            	width: 90,
            	sortable: true,
            	dataIndex: 'maxpatientnum'
            },
            {
            	header: "医院名称", 
            	width: 150,
            	dataIndex: 'hospitalName'
            },
            {
            	header: "科室名称", 
            	width: 100,
            	dataIndex: 'departmentName'
            },
            {
            	header: "医生姓名", 
            	width: 100,
            	dataIndex: 'doctorName'
            }
            ,
            {
            	header: "医生职位", 
            	width: 100,
            	dataIndex: 'doctorTitle'
            }
        ]});
        column.defaultSortable = true;//默认可排序  


        
        
        
        //添加评论面板
    var commentForm = new Ext.FormPanel({
        labelAlign: 'top',
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        width: 490,
        items:[
        	{layout:'column',border:false,labelSeparator:':',
             defaults:{layout: 'form',border:false,columnWidth:.3},
              items:[
                    
                    {items: [{
							xtype:'combo',  
                			fieldLabel:"评价等级",  
                			store:new Ext.data.JsonStore({  
                    		data:{data:[  
                                {id:5,value:"很好"},{id:4,value:"好"},{id:3,value:"一般"},{id:2,value:"差"},{id:1,value:"很差"}]},  
                    		root:"data",  
                    		fields:["id","value"]  
                			}),  
                			editable:false,
                			allowBlank:false,
                    		blankText:'不能为空',
                			emptyText:"请选择评价等级",
                			displayField:"value",  
                			hiddenName: "rank",
							valueField:"id",
                			mode:"local",    
                			triggerAction:"all",
                			anchor:'90%'
                	}]},
                	{ columnWidth:.9,
                		items: [{
                    		xtype:'textarea',
                    		maxLength:100,
                    		maxLengthText:'最大长度100',
                    		fieldLabel: '评语',
                    		id:'addComment',
                    		name: 'comment',
                    		anchor:'90%'
                     }]},
                     {
                		items: [{
                    		xtype:'textarea',
                    		id:'addId',
                    		name: 'treatmentId',
                    		anchor:'90%',
                    		hidden:true
                     }]}
               ]}
               ],
		monitorValid:true,
		
        buttons: [{
            text: '保存',
            formBind: true,
            handler:function(){                   
            	commentForm.getForm().submit({//客户端的数据提交给服务器   
                     url:'commentDoctorPatient.action',      
                     method:'post',
                     waitTitle: '信息', 
                    waitMsg:"正在提交，请稍候。。。",  
                    success: function(form, action){   
                         Ext.MessageBox.alert('信息', '添加成功');
                         commentForm.form.reset();
                 		 commentWindow.hide();
                 		 signStore.reload();
                      },
                     failure:function(form, action){  
                         Ext.MessageBox.alert('错误', '添加失败，请重试'); 
                         commentForm.form.reset();
                 		 commentWindow.hide();
                     }                                  
                 }); 
                 
                }
        },{
            text: '取消',
            handler:function(){
					commentForm.form.reset();
                    commentWindow.hide();
                }
        }]
    });
	//评论窗体
    var commentWindow = new Ext.Window({
	title : '评价医生',
	width : 500,
	height : 250,
	plain : true,
	closeAction : 'hide',// 关闭窗口
	maximizable : false,// 最大化控制 值为true时可以最大化窗体
	layout:'Form',
	items : [commentForm]
});



        
    // create the Grid
    var signGrid = new Ext.grid.GridPanel({
        id:'sign-grid',
        store: signStore,
        cm: column,
        sm: sm,
        height:400,
        width:780,
        title:'预约信息列表',
		loadMask: {msg:'正在加载数据，请稍侯……'},
       /* plugins: new Ext.ux.PanelResizer({
            minHeight: 100
        }),*/
        tbar: [{
        	ref: '../removeBtn',
            iconCls: 'icon-delete',
            text: '删除',
            handler: function(){
            	if(sm.getCount() < 1){
            		Ext.MessageBox.alert("错误","请选择要删除的内容");
            	}
            	else{
            	Ext.MessageBox.confirm("请确认","是否真的要删除指定的内容",function(button,text){
					if(button=="yes"){
						//执行删除操作
						 var s = signGrid.getSelectionModel().getSelections();
                			for(var i = 0, r; r = s[i]; i++){
                    		Ext.Ajax.request({
     							method : 'POST',                             //发送方式.'POST'或'GET',一般是'POST'
     							url: 'deleteSignPatient.action',                  //发送到页面
        						success:function(form,action){                   //发送成功的回调函数
       								Ext.Msg.alert('信息','删除成功');        //弹出对话框
       								signStore.reload();                      //重新读入数据
      							},
     							failure:function(form,action){                          //发送失败的回调函数
       								Ext.Msg.alert("错误", "删除失败");
      							},
     							params:{id : r.get('id')} //发送参数
    						});
                		}			
					}
				});
            	}
            }
        },{
        	ref: '../showPatientCaseBtn',
            iconCls: 'icon-showPatientCase',
            text: '查看病历',
            disabled: true,
            handler: function(){
				if(sm.getCount() != 1){
            		Ext.MessageBox.alert("错误","请选择一条记录查看");
            	}
            	else{
            		var s = signGrid.getSelectionModel().getSelected();
            		window.open("queryPatientCasePatient.action?id="+s.get('id'));
            	}
				
            }
        },{
        	ref: '../commentBtn',
            iconCls: 'icon-comment',
            text: '评价',
            disabled: true,
            handler: function(){
            	if(sm.getCount() < 1){
            		Ext.MessageBox.alert("错误","请选择要评价的内容");
            	}
            	else{
            		var s = signGrid.getSelectionModel().getSelected();
            		commentForm.getForm().findField('addId').setValue(s.get('id'));
            		commentWindow.show();
            	}
            	
            }
        },{
        	ref: '../nowSignBtn',
            iconCls: 'icon-nowSign',
            text: '当前预约',
            handler: function(){
            	signGrid.showPatientCaseBtn.setDisabled(true);
            	signGrid.removeBtn.setDisabled(false);
            	signGrid.commentBtn.setDisabled(true);
				signStore.baseParams = {
                	type:"now"
        		},
                signStore.reload({params:{start:0,limit:10}});
            }
        },{
        	ref: '../historySignBtn',
            iconCls: 'icon-historySign',
            text: '历史预约',
            handler: function(){
            	signGrid.showPatientCaseBtn.setDisabled(false);
            	signGrid.removeBtn.setDisabled(true);
            	signGrid.commentBtn.setDisabled(false);
				signStore.baseParams = {
                	type:"history"
        		},
                signStore.reload({params:{start:0,limit:10}});
            }
        },{
        	ref: '../historySignBtn',
            iconCls: 'icon-commentSign',
            text: '评价记录',
            handler: function(){
            	signGrid.showPatientCaseBtn.setDisabled(false);
            	signGrid.removeBtn.setDisabled(true);
            	signGrid.commentBtn.setDisabled(true);
				signStore.baseParams = {
                	type:"comment"
        		},
                signStore.reload({params:{start:0,limit:10}});
            }
        }],
        bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: signStore,
            displayInfo: true,
			displayMsg:'显示第 {0} 条到 {1} 条记录，一共 {2} 条',  
            emptyMsg:'没有记录'/*,
            plugins: new Ext.ux.ProgressBarPager()*/
        })
    });


    
   signGrid.render('signGrid');
   signStore.baseParams = {
                	type:"now"
        		},
   signStore.load({params:{start:0,limit:10}});

   
   
});